<template>
  <view class="modern-material-container">
    <!-- 顶部导航栏 -->
    <back :showBackText="false" customClass="modern-header" title="分享资料"></back>

    <!-- 主内容区域 -->
    <view class="content-wrapper" v-if="isLoad">
      <scroll-view scroll-y class="modern-scroll">
        <!-- 课程信息卡片 -->
        <view class="material-item detail-card">
          <view class="item-header">
            <view class="item-icon">
              <text class="icon-text">📚</text>
            </view>
            <view class="item-title-section">
              <text class="item-title">课程信息</text>
            </view>
          </view>
          <view class="item-content">
            <view class="info-item">
              <text class="info-label">课程名称</text>
              <text class="info-value">{{ info.name }}</text>
            </view>
            <view class="info-divider" v-if="info.code"></view>
            <view class="info-item" v-if="info.code">
              <text class="info-label">课程代码</text>
              <text class="info-value">{{ info.code }}</text>
            </view>
          </view>
    </view>

        <!-- 分享内容卡片 -->
        <view class="material-item detail-card">
          <view class="item-header">
            <view class="item-icon">
              <text class="icon-text">✍️</text>
            </view>
            <view class="item-title-section">
              <text class="item-title">分享内容</text>
            </view>
          </view>
          <view class="item-content">
            <textarea 
              class="share-textarea" 
              maxlength="128" 
              @input="shareContentTap" 
              :placeholder="'请把您在网盘中保存的《' + info.name + '》课程相关的资料分享给我们，资料采纳后将赠送积分奖励'"
              placeholder-class="textarea-placeholder"
            ></textarea>
          </view>
        </view>

        <!-- 操作按钮区域 -->
        <view class="action-section">
          <view class="action-button primary" @tap="submitTap">
            <text class="action-text">立即提交</text>
          </view>

        </view>
      </scroll-view>
    </view>


  </view>
</template>

<script>
	let app = getApp();
	let that = null;
	let service = app.globalData.service;
	export default {
		data() {
			return {
				id: 0,
				info: [],
				isLoad: false,
				ruleInfo: [],
				shareContent: "",
	
				checkAppIsAudit: true,
			};
		},
		onLoad: function(options) {
			that = this;
			that.id = options.id;
			that.checkAppIsAudit = app.globalData.appIsAudit;
			that.getInfo();
		},
		onShow: function(options) {},
		methods: {
			shareContentTap(options) {
				that.shareContent = options.detail.value;
			},

			async submitTap() {
				let res = await service.saveMaterialShare(that.id, that.shareContent);
				app.showToast('提交成功！');
				setTimeout(() => {
					uni.navigateBack();
				}, 2000);
			},
			async getInfo() {
				let info = await service.courseInfo(that.id);
				let ruleInfo = await service.getMaterialShareRule();
				that.info = info.data;
				that.ruleInfo = ruleInfo.data;
				that.isLoad = true;
			},
		}
	};
</script>
<style src="./share.css"></style>
